home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 3 / Amiga Tools 3.iso / grafik / raytracing / rayshade-4.0.6.3 / fixes / fix009 < prev    next >
Text File  |  1994-08-09  |  6KB  |  213 lines

  1. From theseas!fs.Princeton.EDU!cek Sat, 8 May 93 01:34:11 EET
  2. Received: by kriton.UUCP (V1.16/Amiga)
  3.     id AA00000; Sat, 8 May 93 01:34:11 EET
  4. Received: by theseas.ntua.gr with UUCP; Fri, 7 May 93 14:46:34 +0300
  5. Received: from mcsun.EU.net by pythia.ics.forth.gr via ITEnet with SMTP;
  6.     id AA05390 (5.65c/FORTH-ICS-3.0-MHS-7.0); Fri, 7 May 1993 14:42:23 +0300
  7. Received: by mcsun.EU.net via EUnet
  8.     id AA25040 (5.65b/CWI-2.217); Fri, 7 May 1993 13:37:20 +0200
  9. Received: from Princeton.EDU by relay1.UU.NET with SMTP 
  10.     (5.61/UUNET-internet-primary) id AB16762; Fri, 7 May 93 07:36:31 -0400
  11. Received: from fs.Princeton.EDU by Princeton.EDU (5.65b/2.96/princeton)
  12.     id AA05481; Fri, 7 May 93 07:36:25 -0400
  13. Received: by fs.Princeton.EDU (4.1/1.105)
  14.     id AA25196; Fri, 7 May 93 07:36:24 EDT
  15. Received: from pobox.cscs.ch by fs.Princeton.EDU (4.1/1.105)
  16.     id AA25110; Fri, 7 May 93 07:35:39 EDT
  17. Received: from staff-fddi.cscs.ch by pobox.cscs.ch with SMTP inbound 
  18.           id <5598-0@pobox.cscs.ch>; Fri, 7 May 1993 13:35:28 +0200
  19. Received: from localhost by staff-ether id AA28928; Fri, 7 May 93 13:35:23 +0200
  20. Message-Id: <9305071135.AA28928@staff-ether>
  21. Date: Fri, 07 May 93 13:35:22 +0200
  22. Errors-To: Princeton.EDU!cek
  23. Remailed-Date: Fri May  7 07:35:43 EDT 1993
  24. From: cscs.ch!athurn
  25. To: cs.Princeton.EDU!rayshade-users
  26. Subject: Portable Heighfields (patch)
  27.  
  28.  
  29. Hello Rayshade Users:
  30.  
  31. I finally got around to solving the heightfield portability problem.
  32. The following patch is to be applied to libray/libobj/hf.c. After
  33. recompilation (see notes below), Rayshade and Inetray expect the
  34. heightfield data files to be XDR files (eXternal Data Representation -
  35. the stuff SUN uses for RPC and therefore NFS). Compared to a binary
  36. file, there is a 40 byte overhead but the XDR file is completely
  37. portable.
  38.  
  39. Just patching hf.c and recompiling doesn't change anything. To compile
  40. the new stuff -DXDRHF has to be added to the ccflags in config.sh (and
  41. then Reconfigure has to be run). On some machines (e.g. SGI)
  42. the library containing the xdr-routines have to be added (in the case of
  43. of SGI they reside in libsun.a). Furthermore the compiler has to be
  44. instructed to handle non-ansi c since the SUN header files are not (yet)
  45. ansi clean (on the SGI -cckr has to be added to the ccflags).
  46.  
  47. The patch has been tested on SGIs and on a DECstation (which has
  48. different byte ordering).
  49.  
  50. Following the patch is a short c program (hf2xhf) which converts
  51. old-style binary hf files to the new xhf (XDR heightfield) files.
  52.  
  53. Cheers
  54.     - ant
  55.  
  56. ============= patch.hf.c ================================================
  57. 25a26,30
  58. > #ifdef XDRHF
  59. > #include    <rpc/rpc.h>
  60. > #include    <fcntl.h>
  61. > #define        MAXSIZE        ((u_int)1000000)
  62. > #endif
  63. 48a54,61
  64. > #ifdef XDRHF
  65. > readbuf(fdp,buf,count)
  66. > int *fdp; void *buf; u_int count;
  67. > {
  68. >     return read(*fdp,buf,count);
  69. > }
  70. > #endif
  71. 53,56c66,76
  72. <     Hf *hf;
  73. <     FILE *fp;
  74. <     float val, *maxptr, *minptr;
  75. <     int i, j;
  76. ---
  77. >     Hf         *hf;
  78. >     float     val, *maxptr, *minptr;
  79. >     int     i, j;
  80. > #ifdef XDRHF
  81. >     static int fp;
  82. >     u_int    sqSize;
  83. >     XDR        xdrs;
  84. >     float    *buf;
  85. > #else
  86. >     FILE     *fp;
  87. > #endif
  88. 57a78,80
  89. > #ifdef XDRHF
  90. >     if ((fp = open(filename,O_RDONLY)) < 0) {
  91. > #else
  92. 59a83
  93. > #endif
  94. 76a101,105
  95. > #ifdef XDRHF
  96. >     xdrrec_create(&xdrs,0,0,&fp,readbuf,NULL);
  97. >     xdrs.x_op = XDR_DECODE;
  98. >     if (!xdrrec_skiprecord(&xdrs)) {
  99. > #else
  100. 77a107
  101. > #endif
  102. 81a112,120
  103. > #ifdef XDRHF
  104. >     buf = NULL;
  105. >     if (!xdr_array(&xdrs,&buf,&sqSize,MAXSIZE,
  106. >                    (u_int)sizeof(float),xdr_float)) {
  107. >         RLerror(RL_ABORT, "xdr_array() failed.\n");
  108. >         return (Hf *)NULL;
  109. >     }
  110. >     hf->size = (int)sqrt((double)sqSize);
  111. > #endif
  112. 83a123,125
  113. > #ifdef XDRHF
  114. >         hf->data[i] = &buf[i*hf->size];
  115. > #else
  116. 84a127
  117. > #endif
  118. 87a131
  119. > #ifndef XDRHF
  120. 92a137
  121. > #endif
  122. 108a154,156
  123. > #ifdef XDRHF
  124. >     (void)close(fp);
  125. > #else
  126. 109a158
  127. > #endif
  128. ============= end of patch.hf.c =====================================
  129.  
  130. /*======================================================================
  131.                     H F 2 X H F . C 
  132.                     doc: Fri Apr 30 11:27:46 1993
  133.                     dlm: Fri May  7 11:22:17 1993
  134.                     (c) 1993 ant@bernina.ethz.ch
  135.                     uE-Info: 58 40 T 0 0 72 2 2 4 ofnI
  136. ======================================================================*/
  137.  
  138. #include    <stdio.h>
  139. #include    <fcntl.h>
  140. #include    <rpc/rpc.h>
  141.  
  142. #define        int32        int
  143. #define        float32        float
  144.  
  145. #define        USE_DEFAULT    0
  146.  
  147. static int ofd;                        /* could also be passed */
  148.  
  149. main(ac,av)
  150. int ac; char *av[];
  151. {
  152.     int     ifd,i,writebuf();
  153.     int32    size;
  154.     u_int    sqSize;
  155.     float32    val,*array;
  156.     XDR        xdrs;
  157.     
  158.     if (ac != 3) {
  159.         fprintf(stderr,"Usage: %s <infile> <outfile>\n",av[0]);
  160.         exit(1);
  161.     }
  162.  
  163.     if ((ifd = open(av[1],O_RDONLY)) < 0) {
  164.         perror("open infile");
  165.         exit(1);
  166.     }
  167.     read(ifd,&size,4);
  168.     printf("HF size = %d\n",size);
  169.     sqSize = size*size;
  170.     array = (float32 *)malloc(sqSize*sizeof(float32));
  171.     if (array == NULL) {
  172.         fprintf(stderr,"malloc() failed!\n");
  173.         exit(1);
  174.     }
  175.     for (i=0; i<sqSize; i++) {
  176.         read(ifd,&val,4);
  177.         array[i] = (float32)val;
  178.     }
  179.     close(ifd);
  180.  
  181.     if ((ofd = creat(av[2],0666)) < 0) {
  182.         perror("open outfile");
  183.         exit(1);
  184.     }
  185.     xdrrec_create(&xdrs,USE_DEFAULT,USE_DEFAULT,NULL,NULL,writebuf);
  186.     xdrs.x_op = XDR_ENCODE;
  187.     if (!xdr_array(&xdrs,&array,&sqSize,sqSize,
  188.                    (u_int)sizeof(float32),xdr_float)) {
  189.         fprintf(stderr,"xdr_array() failed!\n");
  190.         exit(1);
  191.     } 
  192.     if (!xdrrec_endofrecord(&xdrs,TRUE)) {
  193.         fprintf(stderr,"xdr_endofrecord() failed!\n");
  194.         exit(1);
  195.     } 
  196.     close(ofd);
  197.  
  198.     exit(0);
  199. }
  200.  
  201. writebuf(dummyParam,buf,count)                    /* write stub */
  202. char *dummyParam,*buf; int count;
  203. {
  204.     return write(ofd,buf,count);
  205. }
  206.  
  207.  
  208. ----------
  209. Administrivia: rayshade-request@cs.princeton.edu
  210. Mailing list: rayshade-users@cs.princeton.edu
  211.  
  212.